//反转链表
//输入：head = [1,2,3,4,5]
//输出：[5,4,3,2,1]
class Solution2 {
    public ListNode reverseList(ListNode head) {
       //判断head为空的情况
        if(head == null){
            return null;
        }
       //当链表只有一个节点的情况
        if(head.next == null){
            return head;
        }
       //多个节点的链表
       ListNode cur = head.next;
       head.next = null;
       while(cur != null){
           ListNode curNext=cur.next;
           cur.next = head;
           head = cur;
           cur = curNext;
       }
       return head;
    }
}